package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.domain.po.Dept;
import com.itheima.domain.po.Emp;
import com.itheima.mapper.DeptMapper;
import com.itheima.mapper.EmpMapper;
import com.itheima.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper,Dept> implements DeptService {
    @Autowired
    EmpMapper empMapper;

    @Override
    public List<Dept> selectAll() {
        List<Dept> list = this.list();
        return list;
    }

    @Override
    public void deleteById(Integer id) {
        QueryWrapper<Emp> queryWrapper = Wrappers.<Emp>query().eq("dept_id", id);
        List<Emp> empList = empMapper.selectList(queryWrapper);
        if (CollectionUtils.isNotEmpty(empList)) {
            this.removeById(id);
        }
    }
}
